package proxy.dynamic;

import proxy.dynamic.impl.JavaDeveloper;

import java.lang.reflect.Proxy;

/**
 * @package proxy.dynamic
 * @Class JavaDynamicProxy
 * @Description TODO
 * @Author zhangxinhua
 * @Date 19-11-25 下午2:10
 */
public class JavaDynamicProxy {
    public static void main(String[] args) {
        JavaDeveloper jDeveloper = new JavaDeveloper();
        Developer developer = (Developer) Proxy.newProxyInstance(jDeveloper.getClass().getClassLoader(), jDeveloper.getClass().getInterfaces(), (proxy, method, params) -> {
            if (method.getName().equals("code")) {
                System.out.println("我是一个特殊的人，code之前先分析问题");
                return method.invoke(jDeveloper, params);
            }
            if (method.getName().equals("debug")) {
                System.out.println("我没有bug");

            }
            return null;
        });
        developer.code();
        developer.debug();
    }
}
